using System;
using IStrong.EC.Abstractions.Interfaces;
using IStrong.EC.DAO.Abstractions.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using IStrong.EC.WebApi.Results.Entity;
using System.Collections.Generic;

namespace IStrong.EC.WebApi.Results.Repository
{
    /// <summary>
    /// 数据访问类
    /// </summary>
    public class Customer : IService
    {
        /// <summary>
        /// 数据库操作组件
        /// </summary>
        private readonly IDbContext _db;

        /// <summary>
        /// 配置信息
        /// </summary>
        private readonly IConfiguration _configuration;

        /// <summary>
        /// 日志组件
        /// </summary>
        private readonly ILogger<Customer> _logger;
        /// <summary>
        /// 注入服务
        /// </summary>
        /// <param name="db"></param>
        /// <param name="configuration"></param>
        /// <param name="logger"></param>
        public Customer(IDbContext db, ILogger<Customer> logger, IConfiguration configuration)
        {
            _db = db;
            _logger = logger;
            _configuration = configuration;
        }

        #region 查询数据

        /// <summary>
        /// 获取老客户信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public IEnumerable<CustomerOldInfo> GetCustomerOldInfos(object param)
        {
            return _db.Query<CustomerOldInfo>("Customer.s_customer_old_info", param);
        }

        /// <summary>
        /// 根据客户ID获取客户跟踪记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public IEnumerable<CustomerOldRecord> GetCustomerOldRecordsById(object param)
        {
            return _db.Query<CustomerOldRecord>("Customer.s_customer_old_record_by_id", param);
        }

        #endregion 查询数据

        #region 添加数据

        /// <summary>
        /// 新增/修改老客户信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int AddCustomerOldInfo(object param)
        {
            return _db.Execute("Customer.iu_customer_old_info", param);
        }

        /// <summary>
        /// 新增客户跟踪记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int AddCustomerOldRecord(object param)
        {
            return _db.Execute("Customer.i_customer_old_record", param);
        }

        #endregion 添加数据

        #region 删除数据

        /// <summary>
        /// 根据客户ID删除客户信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int DelCustomerOldInfoById(object param)
        {
            return _db.Execute("Customer.d_customer_old_info_by_id", param);
        }

        /// <summary>
        /// 根据跟踪记录ID删除记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public int DelCustomerOldRecordById(object param)
        {
            return _db.Execute("Customer.d_customer_old_record_by_id", param);
        }

        #endregion 删除数据
    }
}